package ro.unibuc.hobbygroups.domain.xml;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import ro.unibuc.hobbygroups.domain.Picture;

@XmlRootElement(name = "group")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "group", propOrder = { "title", "subtitle", "image",
		"thumbnail" })
public class Group {

	@XmlElement(required = true)
	private String title;

	@XmlElement(required = true)
	private String subtitle;

	@XmlElement(required = true)
	private String image;

	@XmlElement(required = true)
	private String thumbnail;

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getSubtitle() {
		return subtitle;
	}

	public void setSubtitle(String subtitle) {
		this.subtitle = subtitle;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public String getThumbnail() {
		return thumbnail;
	}

	public void setThumbnail(String thumbnail) {
		this.thumbnail = thumbnail;
	}

	public static Group fromDomain(ro.unibuc.hobbygroups.domain.Group group,
			String downloadUrl, String thumbnailUrl) {
		Group result = new Group();

		Picture picture = group.getPictures().iterator().next();

		result.setTitle(group.getGroupName());
		result.setSubtitle(group.getDescription());
		result.setImage(String.format(downloadUrl, picture.getId()));
		result.setThumbnail(String.format(thumbnailUrl, picture.getId()));

		return result;
	}
}
